package com.youyiwen.Mapper;

import com.youyiwen.Bean.Question;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author: zhaoyang
 * @Date: 2021/03/18
 */
@Mapper
public interface QuestionMapper {
    public void insertQuestion(Question question);


    @Select("select * from Question where tag = #{classify} order by ${way} desc limit #{offSet},#{size}")
    public List<Question> selectQuestions(@Param(value = "classify") String classify,
                                          @Param(value = "way") String way,
                                          @Param(value = "offSet") Integer offSet,
                                          @Param(value = "size")Integer size);


    @Select("select count(1) from question where tag = #{classify}")
    public Integer count(String classify);


    @Select("select * from Question where id = #{id}")
    public Question getById(@Param(value = "id") String id);

    @Update("update question set title = #{title},description = #{description},simp_des =#{simpDes}, gmt_modify=#{gmtModify} where id = #{id}")
    public void updateQuestion(@Param(value="title") String title,
                               @Param(value="description") String description,
                               @Param("simpDes") String simpDes,
                               @Param(value = "gmtModify") Long gmtModify,
                               @Param(value="id") String id);

    @Update("update question set view_count = view_count + 1 where id = #{id}")
    public void updateViewCount(@Param(value = "id") String id);

    @Update("update question set comment_count = comment_count + 1,last_reply_time = #{lastReplyTime} where id = #{id}")
    public void updateQuestionAbout(@Param(value = "id") String id,
                                   @Param(value = "lastReplyTime") Long lastReplyTime);

    @Select("select title from question where id = #{id}")
    public String selectTitleById(String id);

    @Select("select userName from question where id = #{id}")
    public String selectUserNameById(String id);

    @Select("select * from question where userName = #{userName}")
    public List<Question> selectQuestionsByUserName(String userName);

    @Select("select * from question where userName = #{userName} order by view_count limit 5")
    public List<Question> selectHotQuestions(String userName);

    @Delete("delete from question where id = #{id}")
    public void deleteQuestion(String id);


    @Select("select count(*) from question where title regexp #{keyValue}")
    public Integer selectKeyCount(@Param(value = "keyValue") String keyValue);

    public List<Question> selectMainInfo(@Param(value = "offSet") Integer offSet,
                                         @Param(value = "size")Integer size,
                                         @Param(value = "keyValue") String keyValue);
}
